package com.sniff.atp.modules.test.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sniff.atp.common.api.CommonPage;
import com.sniff.atp.common.api.CommonResult;
import com.sniff.atp.modules.test.model.PlatformAddress;
import com.sniff.atp.modules.test.service.PlatformAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: sniff-atp
 * @BelongsPackage: com.sniff.atp.modules.test.controller
 * @Author: zxy
 * @CreateTime: 2024-01-23 17:17
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/test/platformAddress")
@Api(value = "平台地址", tags = "平台地址")
public class PlatformAddressController {
    @Autowired
    private PlatformAddressService platformAddressService;

    @ApiOperation("获取平台地址列表")
    @PostMapping("/list")
    public Object getPlatformAddressList(@RequestBody PlatformAddress platformAddress){
        if(platformAddress.getPageSize() == null || platformAddress.getPageNum() == null || platformAddress.getPageSize() == 0 || platformAddress.getPageNum() == 0){
            platformAddress.setPageSize(10);
            platformAddress.setPageNum(1);
        }

        Page<PlatformAddress> list = platformAddressService.list(platformAddress, platformAddress.getPageSize(), platformAddress.getPageNum());
        return CommonResult.success(CommonPage.restPage(list));
    }

    @ApiOperation("新增平台地址")
    @PostMapping("/create")
    public Object create(@RequestBody PlatformAddress platformAddress){
        boolean create = platformAddressService.create(platformAddress);
        if(create){
            return CommonResult.success(null);
        }else{
            return CommonResult.failed();
        }
    }

    @ApiOperation("修改平台地址")
    @PostMapping("/update")
    public Object update(@RequestBody PlatformAddress platformAddress){
        boolean update = platformAddressService.update(platformAddress.getId(), platformAddress);
        if(update){
            return CommonResult.success(null);
        }else{
            return CommonResult.failed();
        }
    }

    @ApiOperation("删除平台地址")
    @PostMapping("/delete")
    public Object delete(@RequestBody  PlatformAddress platformAddress){
        boolean delete = platformAddressService.delete(platformAddress.getId());
        if(delete){
            return CommonResult.success(null);
        }else{
            return CommonResult.failed();
        }
    }
}
